package cn.admin.config.common.lang.enumeration;

public abstract class IntegerEnum extends Enum {


    protected static IntegerEnum create(int value) {
        return (IntegerEnum)createEnum(value);
    }

    protected static IntegerEnum create(Number value) {
        return (IntegerEnum)createEnum(value.intValue());
    }

    protected static IntegerEnum create(String name, int value) {
        return (IntegerEnum)createEnum(name, value);
    }

    protected static IntegerEnum create(String name, Number value) {
        return (IntegerEnum)createEnum(name, value.intValue());
    }

    protected static Object createEnumType() {

        return new EnumType() {
            @Override
            protected Class<?> getUnderlyingClass() {
                return Integer.class;
            }

            @Override
            protected Number getNextValue(Number value, boolean flagMode) {
                if (value == null) {
                    return flagMode ? new Integer(1) : new Integer(0);
                } else {
                    int intValue = (Integer)value;
                    return flagMode ? new Integer(intValue << 1) : new Integer(intValue + 1);
                }
            }

            @Override
            protected boolean isZero(Number value) {
                return (Integer) value == 0;
            }
        };

    }


    @Override
    public String toHexString() {
        return Integer.toHexString(this.getValue().intValue());
    }

    @Override
    public String toOctalString() {
        return Integer.toOctalString(this.getValue().intValue());
    }

    @Override
    public String toBinaryString() {
        return Integer.toBinaryString(this.getValue().intValue());
    }

    @Override
    public int intValue() {
        return this.getValue().intValue();
    }

    @Override
    public long longValue() {
        return this.getValue().longValue();
    }

    @Override
    public float floatValue() {
        return this.getValue().floatValue();
    }

    @Override
    public double doubleValue() {
        return this.getValue().doubleValue();
    }
}
